package com.zbkj.service.assistant.service;


import com.zbkj.common.constants.RedisConstants;
import com.zbkj.common.model.assistant.AssistantSetting;
import com.zbkj.common.utils.RedisUtil;
import com.zbkj.service.assistant.dao.AssistantSettingDao;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class AssistantSettingBaseServiceImpl extends ServiceImpl<AssistantSettingDao, AssistantSetting>{
    @Autowired
    private RedisUtil redisUtil;

    public AssistantSetting getSetting() {
        Object o = redisUtil.get(RedisConstants.ASSISTANT_SETTING_KEY);
        if (o != null) {
            return (AssistantSetting) o;
        }

        AssistantSetting setting = getById(1);
        redisUtil.set(RedisConstants.ASSISTANT_SETTING_KEY, setting);
        return setting;
    }

    public boolean update(AssistantSetting assistantSetting) {
        assistantSetting.setId(1);
        boolean b = updateById(assistantSetting);
        redisUtil.delete(RedisConstants.ASSISTANT_SETTING_KEY);
        return b;
    }
}

